<?php
/*
 * Copyright (c) 2006 Byrne Reese. All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the BSD License.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *
 * @author Byrne Reese <byrne@majordojo.com>
 * @version 0.1
 */

require_once("lib/config.php");
require_once("examples/ExampleGoogleCheckoutServer.php");
connect_to_db();
$server = new ExampleGoogleCheckoutServer();

$xml1 = <<<END
<new-order-notification xmlns="http://checkout.google.com/schema/2" serial-number="46c40596-982f-43c5-90fa-74e77ceb05e9">
  <timestamp>2006-12-21T06:54:02.855Z</timestamp>
  <shopping-cart>
    <items>
      <item>
        <quantity>1</quantity>
        <unit-price currency="USD">750.0</unit-price>
        <item-name>Test Run</item-name>
        <item-description>Single Site License</item-description>
      </item>
    </items>
  </shopping-cart>
  <order-adjustment>
    <merchant-codes />
    <total-tax currency="USD">0.0</total-tax>
    <adjustment-total currency="USD">0.0</adjustment-total>
  </order-adjustment>
  <google-order-number>849981473283029</google-order-number>
  <buyer-shipping-address>
    <email>byrnereese@gmail.com</email>
    <address1>755 Walker Ave</address1>
    <address2></address2>
    <contact-name>Byrne Reese</contact-name>
    <company-name></company-name>
    <phone></phone>
    <fax></fax>
    <country-code>US</country-code>
    <city>oakland</city>
    <region>CA</region>
    <postal-code>94610</postal-code>
  </buyer-shipping-address>
  <buyer-billing-address>
    <email>byrnereese@gmail.com</email>
    <address1>755 Walker Ave</address1>
    <address2></address2>
    <contact-name>Byrne Reese</contact-name>
    <company-name></company-name>
    <phone></phone>
    <fax></fax>
    <country-code>US</country-code>
    <city>oakland</city>
    <region>CA</region>
    <postal-code>94610</postal-code>
  </buyer-billing-address>
  <buyer-marketing-preferences>
    <email-allowed>true</email-allowed>
  </buyer-marketing-preferences>
  <order-total currency="USD">750.0</order-total>
  <fulfillment-order-state>NEW</fulfillment-order-state>
  <financial-order-state>REVIEWING</financial-order-state>
  <buyer-id>138434689571059</buyer-id>
</new-order-notification>
END;

$xml2 = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<order-state-change-notification xmlns="http://checkout.google.com/schema/2" serial-number="7748c302-1ac0-41b4-b979-68dcde476158">
  <timestamp>2006-08-05T19:14:57.678Z</timestamp>
  <google-order-number>308882055602416</google-order-number>
  <new-fulfillment-order-state>NEW</new-fulfillment-order-state>
  <new-financial-order-state>CHARGEABLE</new-financial-order-state>
  <previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
  <previous-financial-order-state>REVIEWING</previous-financial-order-state>
</order-state-change-notification>
END;

$xml3 = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<risk-information-notification xmlns="http://checkout.google.com/schema/2" serial-number="5d99b350-ebdf-478c-84a8-7e34228a58b4">
<timestamp>2006-08-05T19:14:57.879Z</timestamp>
  <google-order-number>308882055602416</google-order-number>
  <risk-information>
    <billing-address>
      <email>byrne+google1@majordojo.com</email>
      <company-name />
      <contact-name>Byrne Reese</contact-name>
      <phone />
      <fax />
      <address1>755 Walker Ave</address1>
      <address2 />
      <country-code>US</country-code>
      <city>Oakland</city>
      <region>CA</region>
      <postal-code>94610</postal-code>
    </billing-address>
    <ip-address>63.193.114.118</ip-address>
    <eligible-for-protection>false</eligible-for-protection>
    <avs-response>U</avs-response>
    <cvn-response>U</cvn-response>
    <partial-cc-number>1111</partial-cc-number>
    <buyer-account-age>0</buyer-account-age>
  </risk-information>
</risk-information-notification>
END;

$xml4 = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<charge-amount-notification xmlns="http://checkout.google.com/schema/2" serial-number="f4b1807a-b8a6-46fb-b286-21e6c0abd63e">
<timestamp>2006-08-10T06:46:38.381Z</timestamp>
  <google-order-number>932143938337673</google-order-number>
  <latest-charge-amount currency="USD">1.0</latest-charge-amount>
  <total-charge-amount currency="USD">1.0</total-charge-amount>
</charge-amount-notification>
END;

$xml5 = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<merchant-calculation-callback xmlns="http://checkout.google.com/schema/2">
  <shopping-cart>
    <merchant-private-data>
      <merchant-note>affiliate code 01234</merchant-note>
    </merchant-private-data>
    <cart-expiration>
      <good-until-date>2006-12-31T23:59:59.000Z</good-until-date>
    </cart-expiration>
    <items>
      <item>
        <quantity>1</quantity>
        <unit-price currency="USD">35.00</unit-price>
        <item-name>Dry Food Pack AA1453</item-name>
        <item-description>A pack of highly nutritious dried food for emergency</item-description>
        <tax-table-selector>food</tax-table-selector>
      </item>
      <item>
        <quantity>1</quantity>
        <unit-price currency="USD">178.00</unit-price>
        <item-name>MegaSound 2GB MP3 Player</item-name>
        <item-description>Portable MP3 player - stores 500 songs</item-description>
        <merchant-private-item-data>
          <item-note>Popular item: Check inventory and order more if needed</item-note>
        </merchant-private-item-data>
      </item>
    </items>
  </shopping-cart>
  <buyer-language>en_US</buyer-language>
  <buyer-id>294873009217523</buyer-id>
  <calculate>
    <addresses>
      <anonymous-address id="739030698069958">
        <country-code>US</country-code>
        <city>Ventura</city>
        <region>CA</region>
        <postal-code>93003</postal-code>
      </anonymous-address>
      <anonymous-address id="421273450774618">
        <country-code>US</country-code>
        <city>Mountain View</city>
        <region>CA</region>
        <postal-code>94043</postal-code>
      </anonymous-address>
    </addresses>
    <tax>true</tax>
    <shipping>
      <method name="SuperShip" />
      <method name="UPS Ground" />
    </shipping>
    <merchant-code-strings>
      <merchant-code-string code="GiftCert012345" />
      <merchant-code-string code="FirstVisitCoupon" />
    </merchant-code-strings>
  </calculate>
</merchant-calculation-callback>
END;

?>
<html>
  <head>
    <title>Google Checkout Simulator</title>
  </head>
  <body>
    <h1>Google Checkout Simulator</h1>
<?php
if ($_REQUEST['step'] == 1) {
  print "    <p><b>Response sent to Google:</b></p>\n";
  print "    <pre>".htmlentities($server->handle($xml1))."</pre>";
} elseif ($_REQUEST['step'] == 2) {
  print "    <p><b>Response sent to Google:</b></p>\n";
  print "    <pre>".htmlentities($server->handle($xml2))."</pre>";
} elseif ($_REQUEST['step'] == 3) {
  print "    <p><b>Response sent to Google:</b></p>\n";
  print "    <pre>".htmlentities($server->handle($xml3))."</pre>";
} elseif ($_REQUEST['step'] == 4) {
  print "    <p><b>Response sent to Google:</b></p>\n";
  print "    <pre>".htmlentities($server->handle($xml4))."</pre>";
} elseif ($_REQUEST['step'] == 5) {
  print "    <h2>Sending charge-order-notification</h2>\n";
  eval('$server->sendChargeOrderNotification("250493131124632");');
} elseif ($_REQUEST['step'] == 6) {
  print "    <p><b>Response sent to Google:</b></p>\n";
  print "    <pre>".htmlentities($server->handle($xml5))."</pre>";
} else {
  print "    <h2>Start a Real Transaction</h2>\n";
  include("lib/GoogleCheckout.php");
  $cart = new GoogleShoppingCart();
  $item = new CartItem("Test Run","Software","1.00",1);
  $cart->addPrivateData("discountCode","BETA-TEST");
  $cart->addItem($item);
  $cart->acceptDiscounts = 1;
  $cart->callbackURL = CALLBACK_URL;
  print $cart->button->toHTML($cart);
}
?>
    <h2>Simulate a Notification</h2>
    <ul>
      <li><a href="?step=1">New Order Notification</a></li>
      <li><a href="?step=2">Order Status Change Notification</a></li>
      <li><a href="?step=3">Risk Information Notification</a></li>
      <li><a href="?step=4">Charge Amount Notification</a></li>
      <li><a href="?step=5">Send charge-order-notification</a></li>
      <li><a href="?step=6">Merchant Calculation Callback</a></li>
    </ul>
    <hr />
    <p>Software by <a href="http://www.majordojo.com/">majordojo</a></p>
  </body>
</html>